<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>计算器</title>
	</head>

	<body>
		<p>
			整数：<input id="sum1" type="text" />
		</p>
		<p>
			整数：<input id="sum2" type="text" />
		</p>
		<p>
			<button onclick="operation('plus')">相加</button>
			<button onclick="operation('less')">相减</button>
			<button onclick="operation('multiply')">相乘</button>
			<button onclick="operation('except')">相除</button>
		</p>
		<p>
			结果：<input id="result" type="text" />
		</p>
		<script>
			function operation(e) {
				var sum1 = document.querySelector('#sum1').value;
				var sum2 = document.querySelector('#sum2').value;
				var result = document.querySelector('#result');
				switch(e) {
					case 'plus':
						result.value = Number(sum1) + Number(sum2);
						break;
					case 'less':
						result.value = Number(sum1) - Number(sum2);
						break;
					case 'multiply':
						result.value = Number(sum1) * Number(sum2);
						break;
					case 'except':
						result.value = Number(sum1) / Number(sum2);
						break;
				}
			}
		</script>
	</body>

</html>